<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <button id="btn">点我 抽奖！</button>
    <script>
        function my_click() {
            let p = new Promise((resolve, reject) => {
                setTimeout(() => {
                    let num = Math.floor(Math.random() * 100);  //可均衡获取0到9的随机整数。
                    if (num < 31) {
                        resolve(num)
                    } else (reject(num))
                }, 1000)
            })
            p.then((data) => {
                alert('恭喜你已经中奖了哦！' + data)
            })
                .catch((error) => {
                    alert('继续努力！' + error)
                })
        }
        let btn = document.getElementById('btn')
        btn.onclick = my_click
    </script>
</body>

</html>